package com.gmail.dmitryustimov.ms.java7.observer.classic.demo.subj1subsc10event1;

import java.util.ArrayList;
import java.util.List;

public class Subject {

    private List<Observer> subscribers;

    public Subject() {
        subscribers = new ArrayList<>();
    }

    public void makeEvent() {
        notifyObservers(new Event(""));
    }

    public void registerObserver(Observer o) {
        subscribers.add(o);
    }

    public void removeObserver(Observer o) {
        subscribers.remove(o);
    }

    public void notifyObservers(Event event) {
        for (Observer o: subscribers) {
            o.update(event);
        }
    }
}
